Skip to content

feat: template referral system in echo-start#726

Open
285729101 wants to merge 2 commits intoMerit-Systems:masterfrom
285729101:feat/template-referral
Open

feat: template referral system in echo-start#726
285729101 wants to merge 2 commits intoMerit-Systems:masterfrom
285729101:feat/template-referral

Conversation

@285729101
Copy link

Summary

Implements #612 - Template referral system for external templates.

  • When a user scaffolds from an external template via echo-start, the CLI now reads an echo.config.json from the template for a referralCode field
  • If found, the referral code is written to .env.local with the appropriate framework prefix (NEXT_PUBLIC_ECHO_REFERRAL_CODE, VITE_ECHO_REFERRAL_CODE, etc.) so the OAuth flow auto-registers the template creator as the referrer on the new app
  • The echo.config.json is cleaned up after processing since it's template metadata, not app code
  • Template creators can include { "referralCode": "<their-code>" } in echo.config.json to earn referral rewards when others use their template

How it works

  1. Template creator adds echo.config.json to their template repo:
    { "referralCode": "abc-123-def-456" }
  2. User scaffolds: npx echo-start --template https://github.com/creator/template --app-id <id>
  3. echo-start reads the referral code, writes it to .env.local, and removes the config file
  4. When the user's app runs and authenticates via OAuth, the referral code is available to register the template creator as referrer

Closes #612

Test plan

  • Verify echo-start with an external template containing echo.config.json with referralCode writes the code to .env.local
  • Verify echo-start with an external template without echo.config.json works unchanged
  • Verify echo.config.json is removed from the scaffolded project after processing
  • Verify the correct framework-prefixed env var name is used (Next.js, Vite, CRA)
  • Verify built-in templates are unaffected by this change

When scaffolding from an external template, echo-start now reads
echo.config.json for a referralCode and writes it to .env.local
so the OAuth flow auto-registers the template creator as referrer.

Closes Merit-Systems#612
@vercel
Copy link
Contributor

vercel bot commented Feb 18, 2026

@285729101 is attempting to deploy a commit to the Merit Systems Team on Vercel.

A member of the Team first needs to authorize it.

const currentEnv = readFileSync(envFilePath, 'utf-8');
writeFileSync(
envFilePath,
currentEnv.trimEnd() + `\n${referralEnvVar}=${referralCode}\n`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unsanitized referral code from echo.config.json allows environment variable injection into .env.local

Fix on Vercel

@285729101
Copy link
Author

@rsproule this builds on the approach you discussed in #612 — auto-detects the template framework and injects the referral env var accordingly. Let me know if the direction is right.

Add sanitizeReferralCode() that validates referral codes from
echo.config.json against a strict alphanumeric allowlist pattern
before writing to .env.local. Malicious template authors could
previously inject arbitrary environment variables via newlines
or special characters in the referralCode field.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Template referral system

1 participant

Comments